package schema.controller;

import controller.*;
import java.sql.ResultSet;
import java.util.Vector;
import schema.model.SchemaTable;

public class SchemaTableMgr extends DbManager {
    public static final SchemaTableMgr mgr = new SchemaTableMgr();

    private SchemaTableMgr() {
        super( "TABLES" );
        m_titles = new String[]{"NOMBRE", "DESCRIPCION" };
        m_nConnection = 1;
    }

    @Override
    protected SchemaTable getBean() {
        return new SchemaTable();
    }

    @Override
    public SchemaTable getItem( String id ) {
        return (SchemaTable) super.getItem( id );
    }

    @Override
    @SuppressWarnings("unchecked")
    protected void addObject( Vector v, ResultSet rs ) {
        v.add( new SchemaTable( rs ) );
    }

    public synchronized Vector<SchemaTable> getAllTables(String idMod) {
        return executeQuery( "SELECT * FROM `Tables` T where TABLE_NAME not in (select TABLE_NAME FROM TablePortlet where idPortlet='" + idMod + "')" );
    }

    public synchronized Vector<SchemaTable> getTablesModulo( String idMod ) {
        return executeQuery( "SELECT * FROM `Tables` T where TABLE_NAME in (select TABLE_NAME FROM TablePortlet where idPortlet='" + idMod + "')" );
    }

    public void addTablatoPortlet(String idTabla, String idPortlet) {
        mgr.execute("insert into TablePortlet(TABLE_NAME, idPortlet) values('"+idTabla+"', '"+idPortlet+"')");
    }

    public void deleteTablaPortlet(String idTabla, String idPortlet) {
        mgr.execute("delete from TablePortlet where TABLE_NAME ='"+idTabla+"' and idPortlet='"+idPortlet+"'");
    }
}